package LeetCode;

/**
 * @Classname LC99
 * @Description [Tree] // https://leetcode-cn.com/problems/recover-binary-search-tree/
 * @Date 2021/4/19 10:52
 * @Created by yin
 */
public class LC99 {
    TreeNode t1, t2, pre;
    public void recoverTree(TreeNode root) {
        inorder(root);
        int temp = t1.val;
        t1.val = t2.val;
        t2.val = temp;
    }
    public void inorder(TreeNode root){
        if (root == null) return ;
        inorder(root.left);
        if (pre != null && pre.val > root.val) {
            if (t1 == null) t1 = pre;
            t2 = root;
        }
        pre = root;
        inorder(root.right);
    }
}
